package com.atguigu.juc.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * 当前线程的中断标识为true，是不是就立刻停止？
 *
 * @author yfstart
 * @create 2022-07-05 13:14
 */
public class InterruptDemo2 {
  public static void main(String[] args) {
    // 实例方法interrupt()仅仅是设置线程的中断状态为true，不会停止线程
    Thread t1 = new Thread(() -> {
      for (int i = 1; i <= 300; i++) {
        System.out.println("-----：" +i);
      }
      System.out.println("t1 线程调用 interrupt() 后的中断标识02：" + Thread.currentThread().isInterrupted()); // true
    }, "t1");
    t1.start();

    System.out.println("t1 线程默认的中断标识：" + t1.isInterrupted()); // false

    try { TimeUnit.MILLISECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace();}
    t1.interrupt(); // true
    System.out.println("t1 线程调用 interrupt() 后的中断标识01：" + t1.isInterrupted()); // true

    try { TimeUnit.MILLISECONDS.sleep(2000); } catch (InterruptedException e) { e.printStackTrace();}
    System.out.println("t1 线程调用 interrupt() 后的中断标识03：" + t1.isInterrupted()); // ???
  }
}
